//-------------------------------------------------------------------
//	Copyright (c) 2010-2012  Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_UNIFORM_MANAGER_H
#define _UX_UNIFORM_MANAGER_H

#include <Includes.h>

namespace Engine
{
namespace RenderUtils
{

	//
	// Uniform Value
	//
	
	class _EXPORT_ CUniformValue
	{
		friend class CUniformManager;

	public:
		typedef void (*PSetValueToUniformProc_t)(const void *pThis, GLuint uLocation);
		typedef void (*PAddValueToBufferProc_t)(const void *pThis, void *pBuffer);
		
	private:
		void const	*				_pThis;
		PSetValueToUniformProc_t	_pSet;
		PAddValueToBufferProc_t		_pAdd;
		string						_sName;
		gl_uniform::type			_eType;
				
	public:
		CUniformValue(const char *pName, gl_uniform::type eType, const void *pThis,
						PSetValueToUniformProc_t pSetProc, PAddValueToBufferProc_t pAddProc):
			_pThis(pThis), _pSet(pSetProc), _pAdd(pAddProc), _sName(pName), _eType(eType)
		{}
			
		void SetValue(GLuint uLocation)	const	{ _pSet( _pThis, uLocation ); }
		void AddValue(void *pBuffer)	const	{ _pAdd( _pThis, pBuffer ); }
			
		const string &	 GetName()	const	{ return _sName; }
		gl_uniform::type GetType()	const	{ return _eType; }
	};



	//
	// Uniform Manager
	//

	class _EXPORT_ CUniformManager : public CEngBaseObject
	{
		friend class CoreSystems::CRender;

	protected:
		typedef pod_array< CUniformValue *>		values_array_t;

		values_array_t	_aValues;
		
	protected:
		CUniformManager();
		~CUniformManager();

		virtual void Release();
		
		static void _s_DummySetValueToUniform(const void *pThis, GLuint uLocation);
		static void _s_DummyAddValueToBuffer(const void *pThis, void *pBuffer);

	public:
		bool Add(const CUniformValue &cValue);
		bool Remove(const string &sName);

		bool GetValue(const string &sName, CUniformValue *&pValue) const;
	};

//-------------------------------------------------------------------

}	// RenderUtils
}	// Engine

#endif	// _UX_UNIFORM_MANAGER_H